/**
 *******************************************************************************
 * \brief   CAS EBX Project Work "Kaffeemaschine"
 *
 * \file    channel.h
 * \version 1.0
 * \date    30.06.2010
 * \author  Baehler Thomas, Liechti Beat, Sauter Marc,
 * \author  Vuksic Valentina, Zbinden Rene
 *
 * \remark  Last Modifications:
 * \remark  V1.0, 30.06.2010   Initial release
 * \remark  V1.1, 01.07.2010   First working implementation of channel with fifo
 * \remark  V1.2, 01.07.2010   Added R & W semaphore, blocking write (bug) 
 * \remark  V1.3, 07.07.2010   Using message queue instead of fifo
 * \remark  V1.4  12.07.2010   Updating documentation for doxygen
 *******************************************************************************
 **/

#ifndef CHANNEL_H_
#define CHANNEL_H_

/*
 *******************************************************************************
 * Imports (required for ADT structure)
 *******************************************************************************
 */

#include <mqueue.h>
#include <semaphore.h>

/*
 *******************************************************************************
 * Global Type Definition (ADT Structure)
 *******************************************************************************
 */
/** \brief ADT structure for channel */
typedef struct _tChannel
{
	/** \brief name of the message queue and the semaphore as well */
	char *name;
	/** \brief path of the message queue and the semaphore as well */
	char *path;
	/** \brief size of a data item */
	int itemsize;
	/** \brief message queue structure */
	mqd_t queue;
	/** \brief semaphore for reading */
	sem_t *semRead;
	/** \brief semaphore for writing */
	sem_t *semWrite;
} tChannel;

/*
 *******************************************************************************
 * Global Function Declaration
 *******************************************************************************
 */
extern int createChannel(char *name, int itemsize);
extern void deleteChannel(char *name);
extern tChannel *openChannelRead(char *name, int itemsize);
extern tChannel *openChannelWrite(char *name, int itemsize);
extern void closeChannel(tChannel *channel);
extern int readChannel(tChannel *channel, void *data);
extern int writeChannel(tChannel *channel, void *data);

#endif /* CHANNEL_H_ */
